CFLAGS:= -g `sdl2-config --cflags`
LDFLAGS:= `sdl2-config --libs` -lSDL2_ttf -lSDL2_image -lm -lavformat
FFLAGS:= #-fsanitize=thread
CXX:= gcc #-pg
PROG:= cmus-rg
DESTDIR:=
PREFIX:=

OBJS:= init.o metadata.o commands.o graphics.o input.o util.o parser.o cmus-rg.o main.o

all: $(PROG)

%.o: src/%.c src/%.h src/def.h
	$(CXX) $(CFLAGS) -c $<

$(PROG): $(OBJS)
	$(CXX) -Wall -Wextra -std=c99 -pedantic $(FFLAGS) -g $(OBJS) -o $(PROG) $(LDFLAGS)

install: all
	@echo installing executable file to ${DESTDIR}${PREFIX}/bin
	@mkdir -p ${DESTDIR}${PREFIX}/bin
	@cp -f cmus-rg ${DESTDIR}${PREFIX}/bin
	@chmod 755 ${DESTDIR}${PREFIX}/bin/cmus-rg
	@echo installing font file to ${DESTDIR}${PREFIX}/usr/share/fonts/TTF
	@mkdir -p ${DESTDIR}${PREFIX}/usr/share/fonts/TTF
	@cp -f src/font/mplus-1m-regular.ttf ${DESTDIR}${PREFIX}/usr/share/fonts/TTF

uninstall:
	@echo removing executable file from ${DESTDIR}${PREFIX}/bin
	@rm -f ${DESTDIR}${PREFIX}/bin/cmus-rg
	@echo removing font file from ${DESTDIR}${PREFIX}/usr/share/fonts/TTF
	@rm -f ${DESTDIR}${PREFIX}/usr/share/fonts/TTF/mplus-1m-regular.ttf

clean:
	rm -f $(PROG) *.o